package org.csu.molediary.api.controller.front;

import org.csu.molediary.api.common.CommonResponse;
import org.csu.molediary.api.entity.Commentinfo;
import org.csu.molediary.api.service.CommentInfoService;
import org.csu.molediary.api.vo.CommentInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.sql.Date;
import java.util.List;

@Controller
@RequestMapping("/comment/")
public class CommentInfoController {

    @Autowired
    private CommentInfoService commentInfoService;

    //发送评论
    @PostMapping("setcomment")
    @ResponseBody
    //保存发出评论
    public CommonResponse<Commentinfo> saveComment(@RequestParam("comment")String comment, @RequestParam("commented")String commented,
                                                   @RequestParam("comcontent")String comcontent, @RequestParam("diaryid")int diaryid,
                                                   @RequestParam("date")String datetime){
        Commentinfo commentinfo=new Commentinfo();
        commentinfo.setComment(comment);
        commentinfo.setCommented(commented);
        commentinfo.setComcontent(comcontent);
        commentinfo.setDiaryid(diaryid);
        commentinfo.setDate(datetime);

        return commentInfoService.saveCommentinfo(commentinfo);
    }

    @GetMapping("information/{id}")
    @ResponseBody
    //获得某用户被评论信息
    public CommonResponse<List<Commentinfo>> getInformationByCommented(@PathVariable("id")String commented){
        return commentInfoService.queryCommentinfoByCommented(commented);
    }

    @GetMapping("informationbydiary/{id}")
    @ResponseBody
    //通过日记id查到评论信息
    public CommonResponse<List<CommentInfoVO>> getInformationByDiaryId(@PathVariable("id")int id){

        return commentInfoService.queryCommentInfoByDiaryId(id);
    }
}
